#coding=utf8
#-------------------------------------------------------------------------------
# Name:        ??1
# Purpose:
#
# Author:      weigun
#
# Created:     11-08-2011
# Copyright:   (c) weigun 2011
# Licence:     <your licence>
#-------------------------------------------------------------------------------
#!/usr/bin/env python
import sqlite3
import time
import os,sys
import pickledb

class Mock(object):
    """
        class comment
    """

    def __init__(self):
        print 'connect db error use mock instand of it'

    def __getattr__(self,name):
        return lambda: True

class DataSet(object):
    """
        class comment
    """
    DB = 'crashInfo'

    def  __init__(self):
        try:
            if os.path.exists(self.DB):
                self.dbh = sqlite3.connect(self.DB)
            else:
                self.dbh = Mock()
        except Exception:
            self.dbh = Mock()

    def add(self,crash_data):
        sql = u"insert into info " + u"(detail,datetime) values(?,?)"
        values = (crash_data,time.time())
        self.dbh.execute(sql,values)

    def update_times(self,detail):
        pass
        #sql = u"UPDATE info SET times = '%s' WHERE ID = 6;"

    def commit(self):
        self.dbh.commit()

if __name__ == '__main__':
    #a = Mock()
    #a.db()
    #'''
    local_db = pickledb.load('avg_fps.db', False)
    local_db.dcreate('bug')
    local_db.dadd('bug',('times',1))
    local_db.dadd('bug',('update',time.time()))
    local_db.dump()

